float totalScores[] = {0,0,0};
float maxPoints[] = {0,0,0};
float levelScores[] = {0,0,0};
float levelPercs[] = {0.0,0.0,0.0};
float totalPercs[] = {0.0,0.0,0.0};
int minScore = 8;
PFont fontB;

void scoreSetup() {
    fontB = loadFont("SakkalMajallaBold-100.vlw");
    //load scores
    String [] inScores = loadStrings("scores.txt");
    for(int i = 0; i < inScores.length ; i++){
      String[] splitter = split(inScores[i],",");
      float[] splitter2 = float(splitter);
      totalScores[i] = splitter2[1];
      maxPoints[i] = splitter2[2];
      levelScores[i] = splitter2[3];
    }
}

void score(String userInput, String compInput) {
  int[] userElems = int(split(userInput,":"));
  int[] compElems = int(split(compInput,":"));
  
  levelScores[difficulty] = 3;
  if(userElems.length == 1)
  {
    levelScores[difficulty] = 3;
    userSystem.isValid = false;
  }
  else if(userElems.length != compElems.length)
  {
    levelScores[difficulty] = -(max(userElems.length, compElems.length) - min(userElems.length, compElems.length));
    println("element strings not equals");
  }
  
  int j = 0;
  for(int i = 0; i < min(userElems.length, compElems.length);i++)
  {
    if(userElems[i] == compElems[i])
    {
      levelScores[difficulty]++;
    }
    else
    {
      j++;
      while((i+j) < compElems.length)
      {
        if(userElems[i] == compElems[i+j])
        {
          levelScores[difficulty]++;
          break;
        }
        j++;
      }
    }
  } 
  
  maxPoints[difficulty] = 10*(userLevel[difficulty]);
  totalScores[difficulty] += levelScores[difficulty];
  println(totalScores[difficulty]);
  println(maxPoints[difficulty]);
  levelPercs[difficulty] = levelScores[difficulty]/10*100;
  totalPercs[difficulty] = totalScores[difficulty]/maxPoints[difficulty]*100;
}

void displayScores() {
 textFont(fontB, 100);
 if(levelScores[difficulty] < minScore+difficulty)
   fill(255,0,0);
 else
   fill(0,255,0);
 text("Level Score", 30, 300);
 text((int)levelPercs[difficulty] + "%", 130, 400); 
 text("Total Score", 500, 300);
 text((int)totalPercs[difficulty] + "%", 600, 400);
}

void saveScores(){
  String scores[] = new String[3];
  for(int i = 0; i < 3; i++) {
    scores[i] = ""+i+ ","+totalScores[i]+","+maxPoints[i]+","+levelScores[i]+","+userLevel[i];
  }
  saveStrings("scores.txt", scores);
}

void clearScores(){
  for(int i = 0; i < 3; i++) {
    clearScores(i);
  }
}

void clearScores(int difficulty)
{
  int i = difficulty;
  totalScores[i] = 0;
  maxPoints[i] = 0;
  levelScores[i] = 0;
  userLevel[i] = 1;
  saveScores();
}
  
  
  
  
